﻿var ItemOrders = {

    Init: function (opts) {
        var options =
        $.extend(
            {},
            {
                url: "/OrdersStation/Orders/EditSingleOrderItem"
            },
            opts);

        var itemEdit = $("#itemEdit");
        itemEdit.dialog({ autoOpen: false });

        $('#itemInOrderForm').submit(function () {
            // Maybe show a loading indicator...
            $.post(this.action, $(this).serialize(), function (res) {
                // Do something with the response `res`
                // Don't forget to hide the loading indicator!
                itemEdit.dialog("close");
                OrderDetails.reloadList(res.Data);
            });

            $('#itemEditForm').html("");
            return false; // prevent default action
        });

        $(".itemList li a").click(function () {
            $("#itemEditForm").load(options.url + "?itemId=" + $(this).data("id"));

            itemEdit.find("#ItemId").val($(this).data("id"));
            
            itemEdit.dialog("open");
        });
    }
};